package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.core.exception.SysExceptionEnum;
import cc.lj.internal.core.http.HttpResult;
import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.application.service.CapBatchAppService;
import cc.lj.internal.coupons.interfaces.dto.CapBatchDTO;
import cc.lj.internal.coupons.interfaces.dto.command.InsertCapBatchCommand;
import cc.lj.internal.coupons.interfaces.dto.command.UpdateCapBatchCommand;
import cc.lj.internal.coupons.interfaces.dto.query.CapBatchQuery;
import com.sun.scenario.effect.impl.sw.java.JSWBrightpassPeer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;

/**
 * 封顶额批次表接口
 * @author liangxifeng
 * @date 2021-12-20
 */
@RestController
@Slf4j
@Validated
@Api(tags = "封顶额活动批次表接口")
@RequestMapping("capBatch")
public class CapBatchController {
    @Resource(name = "capBatchAppService")
    private CapBatchAppService capBatchAppService;

    /**
     * 新增封顶额活动批次
     * @param addCmd 新增活动批次表command
     * @return 新增后的主键
     */
    @PostMapping("/add")
    @ApiOperation(value = "封顶额活动批次表新增表接口",notes = "错误码：1005001001,1005001019,1005001011,1005001013,1005001021,1005001023,1005001017")
    public HttpResult<Integer> save(@Valid @RequestBody InsertCapBatchCommand addCmd)
    {
        Integer saveRes = capBatchAppService.save(addCmd);
        log.info("新增活动批次controller结果="+saveRes);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),saveRes);
    }
    /**
     * 更新活动批次信息
     * @param updateCmd 更新封顶额活动批次表command
     * @return 影响行数
     */
    @PostMapping("/updateById")
    @ApiOperation(value = "根据ID更新活动封顶额活动批次表数据",notes = "错误码：1005001005,1005001007,1005001019,1005001011,1005001006,1005001025,1005001051")
    public HttpResult<Integer> updateById(@Valid @RequestBody UpdateCapBatchCommand updateCmd)
    {
        log.info("修改封顶额批次表controller入参="+updateCmd);
        Integer res = capBatchAppService.updateById(updateCmd);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),res);
    }
    /**
     * 通过活动批次表主键获取封顶额活动批次数据
     * @param id 主键
     * @return 封顶额活动批次表单条数据DTO
     */
    @GetMapping("/getById")
    @ApiOperation(value = "通过主键获取封顶额活动批次表单条数据",notes = "错误码：1005001007")
    public HttpResult<CapBatchDTO> getById(@Min(1) @RequestParam Integer id) {
        CapBatchDTO capBatchDTO = capBatchAppService.getById(id);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),capBatchDTO);
    }
    /**
     * 封顶额活动批次表查询列表接口
     * @param pageParam<CapBatchQuery> 封顶额活动批次表查询query
     * @return 封顶额活动批次list
     */
    @PostMapping("/getPage")
    @ApiOperation(value = "封顶额活动批次表查询列表接口",notes = "错误码：1005001019")
    public HttpResult<PageBean<CapBatchDTO>> getPage(@Valid @RequestBody PageParam<CapBatchQuery> pageParam) {
        PageBean<CapBatchDTO> pageBean = capBatchAppService.selectPage(pageParam);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),pageBean);
    }

    /**
     * 通过主键删除
     * @param id
     * @return 影响行数
     */
    @PostMapping("/deleteById")
    @ApiOperation(value = "通过主键删除封顶额活动批次表接口",notes = "错误码：1005001007,1005001017,1005001006,1005001027,1005001053")
    public HttpResult<Integer> deleteById(@Min(1) @RequestParam Integer id ) {
        //通过主键删除封顶额批次数据
        Integer rows = capBatchAppService.deleteById(id);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),rows);
    }
}
